import React, { FC, useRef } from "react";

const UseRefDemo: FC = () => { 
    const inputRef = useRef<HTMLInputElement>(null)
    function selectInput() {
        const inputElem = inputRef.current
        console.log(inputElem);
        
        if (inputElem) {
            
            inputElem.select()

        }

    }
    return (
        <div>
            <input type="text" defaultValue="123"  ref={inputRef}/>
            <button onClick={selectInput}>选中input</button>
        </div>
    )

}
export default UseRefDemo;